/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import vical.action.EntryDialogAction;
import vical.model.Internationalization;
import java.awt.event.KeyEvent;

/**
 * The ActionPanel, responsible for some global actions. Like a Tool-bar.
 * 
 * @author Can
 * @author Flora
 */
public class TopPanel extends JPanel {

    // Components
    private JButton addEntryButton;
    private JLabel opacityLabel;
    private JSlider opacitySlider;
    private MainWindow mainWindow;
    private JPanel leftPanel;
    private JPanel rightPanel;

    public JButton getAddEntryButton() {
        return addEntryButton;
    }

    public TopPanel(MainWindow mainW) {
        this.mainWindow = mainW;
        initComponents();
    }
    
    public Component getTransparencyChanger() {
        return rightPanel;
    }

    private void initComponents() {

        // Some initialization, need to pass in a reference to MainWindow for opacity control
        addEntryButton = new JButton(new EntryDialogAction(mainWindow));
        addEntryButton.putClientProperty("JButton.buttonType", "segmented");
        addEntryButton.putClientProperty("JButton.segmentPosition", "only");
        addEntryButton.putClientProperty("JComponent.sizeVariant", "regular");
        addEntryButton.setToolTipText(Internationalization.getString("tooltip_addtask_button"));

        // Components for opacity seeting
        opacityLabel = new JLabel(Internationalization.getString("calendar_opacity_label"));
        opacitySlider = new JSlider(60, 100, 100);
        opacitySlider.setToolTipText(Internationalization.getString("tooltip_opacity_slider"));
        opacitySlider.addChangeListener(new ChangeListener() {

            public void stateChanged(ChangeEvent ce) {
                mainWindow.setOpacity(((float) opacitySlider.getValue()) / 100.0f);
            }
        });

        // Ugly solution to layout: two more panels
        leftPanel = new JPanel();
        leftPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 2));
        leftPanel.add(addEntryButton);

        rightPanel = new JPanel();
        rightPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 4, 2));
        rightPanel.add(opacityLabel);
        rightPanel.add(opacitySlider);

        // Put all together
        this.setPreferredSize(new Dimension(WIDTH, 32));
        this.setLayout(new BorderLayout());
        this.add(BorderLayout.WEST, leftPanel);
        this.add(BorderLayout.EAST, rightPanel);
    }
}
